package prerequisite_qianti;

public class Main2 {
    public static void fun1(Animal a){

    }

    public static Animal fun2(){
        Dog dog=new Dog("小黑",3);
        return dog;
    }

    public static void main(String[] args) {

        //重写的三同一不同->返回值类型，参数列表，方法名相同，方法体不同
        //在Dog和Bird类中重写了父类中的eat方法
        Animal animal=new Dog("旺财",1);
        animal.eat();
        Animal animal1=new Bird("小鸟",2);
        animal1.eat();

    }
}

class Animal{
    public String name;
    int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(name + " 正在吃...");
    }

}

class Dog extends Animal {
    public Dog() {
    }

    public Dog(String name,int age){
        super(name,age);
    }

    public void bark(){
        System.out.println(name + " 正在叫...");
    }

    public void eat(){
        System.out.println(name + " 正在吃狗粮...");
    }

}

class Bird extends Animal {
    public Bird() {
    }

    public Bird(String name, int age) {
        super(name, age);
    }

    public void fly(){
        System.out.println(name + "正在飞");
    }

    public void eat(){
        System.out.println(name + " 正在吃鸟粮...");
    }
}